<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    {{message}} {{message + message}}
    <div :id="message"></div>
    <ul>
      <!-- <li v-for="item in list">
        <span v-if="item.del">{{item.title}}</span>
        <span v-else style="text-decoration: line-through;">{{item.title}}</span>
        <button v-show="!item.del">删除</button>
      </li>
      <todo-item v-for="item in list" :title="item.title" :del="item.del"></todo-item> -->
      <todo-list>
        <todo-item @delete="handleDelete" v-for="item in list" :title="item.title" :del="item.del">
          <template v-slot:pre-icon="{value}">
            <span>前置图标 {{value}}</span>
          </template>
          <!-- <template v-slot:suf-icon>
            <span>后置图标</span>
          </template> -->
        </todo-item>
      </todo-list>
    </ul>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script>
    Vue.component('todo-item', {
      props: {
        title: String,
        del: {
          type: Boolean,
          default: false,
        }
      },
      template: `
      <li>
        <slot name="pre-icon" :value="value">🤭</slot>
        <span v-if="del">{{title}}</span>
        <span v-else style="text-decoration: line-through;">{{title}}</span>
        <slot name="suf-icon">😄</slot>
        <button v-show="!del" @click="handleClick">删除</button>
      </li>
      `,
      data: function () {
        return {
          value:Math.random()
        }
      },
      methods: {
        handleClick() {
          console.log('点击删除按钮')
          this.$emit('delete', this.title)
        }
      }
    })
    Vue.component('todo-list', {
      template: `
      <ul>
      <slot></slot>
      </ul>
      `,
      data: function () {
        return {
          list: [
            {
              title: '课程1',
              del: false
            },
            {
              title: '课程2',
              del: true
            },
            {
              title: '课程3',
              del: false
            },
          ],
        }
      },
      methods: {
        handleDelete(val) {
          console.log('handleDelete', val)
        }
      }
    })
    var vm = new Vue({
      el: '#app',
      data: {
        message: 'hello world',
        list: [
          {
            title: '课程1',
            del: false
          },
          {
            title: '课程2',
            del: true
          },
          {
            title: '课程3',
            del: false
          },
        ],
        list1: [
          {
            title: '课程1',
            del: false
          },
          {
            title: '课程2',
            del: true
          },
        ],
      }
    })
  </script>
</body>

</html>